﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <!-- jsp文件头和头部 -->
    <%@ include file="../admin/top.jsp" %>
    <style>
        table tr td img {
            height: 25px;
            border-radius: 8%;
        }
    </style>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <form action="operation/list/${type}" method="post" name="userForm" id="userForm">
                    <input type="hidden" name="menuId" value="${page.menuId}">
                    <input type="hidden" id="type" value="${type}">
                    <table style="width: 950px">
                        <tr>
                            <td>
                                <c:if test="${userType != 1}">
										<span class="input-icon">
											<input style="margin-top: 0px;width: 85%" autocomplete="off" type="text"
                                                   name="searchValue" value="${page.searchValue}" placeholder="登录账号"
                                                   id="nav-search-input"/>
										</span>
                                </c:if>
                            </td>
                            <td>
									<span class="input-icon">
										<input style="margin-top: 0px;width: 85%" autocomplete="off" type="text"
                                               name="role" value="${role}" placeholder="用户角色" id="nav-search-input"/>
									</span>
                            </td>
                            <td>
									<span class="input-icon">
										<input style="margin-top: 0px;width: 85%" autocomplete="off" type="text"
                                               name="ip" value="${ip}" placeholder="ip" id="nav-search-input"/>
									</span>
                            </td>
                            <td>
									<span>
										<input class="span10 date-picker" name="startTime" id="startTime"
                                               value="${startTime}" type="text" data-date-format="yyyy-mm-dd"
                                               readonly="readonly"
                                               style="width:88px;display: table-cell;font-size: 12px;float: left"
                                               placeholder="开始日期" title="开始日期"/>
										<input class="span10 date-picker" name="endTime" id="endTime" value="${endTime}"
                                               type="text" data-date-format="yyyy-mm-dd" readonly="readonly"
                                               style="width:88px;display: table-cell;font-size: 12px;float:left;"
                                               placeholder="结束日期" title="结束日期"/>
									</span>
                            </td>
                            <td style="vertical-align:top;">
                                <button class="btn btn-mini btn-light" type="button" onclick="search();" title="检索">
                                    <i id="nav-search-icon" class="icon-search"></i>
                                </button>
                            </td>
                            <td style="vertical-align:top;">
                                <c:if test="${fn:contains(butSet, 'del')}">
                                    <a class="btn btn-small btn-success" onclick="batchDel();">批量删除</a>
                                </c:if>
                            </td>
                        </tr>
                    </table>
                    <!-- 检索  -->
                    <table id="table_report" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>
                                <input onclick="selectAll(this)" role='checkbox' type='checkbox' class='cbox checkbox'
                                       style="opacity: 1;position: relative"/>
                            </th>
                            <th>ID</th>
                            <th>登录账号</th>
                            <th>角色</th>
                            <c:choose>
                                <c:when test="${type == 1}">
                                    <th>账号类型</th>
                                    <th>解绑方式</th>
                                </c:when>
                                <c:when test="${type == 2}">
                                    <th>账号类型</th>
                                    <th>录入方式</th>
                                </c:when>
                                <c:when test="${type == 3}">
                                    <th>账号类型</th>
                                    <th>删除方式</th>
                                </c:when>
                                <c:when test="${type == 4}">
                                    <th>渠道归属</th>
                                    <th>操作模块</th>
                                    <th>操作行为</th>
                                </c:when>
                            </c:choose>
                            <th>操作描述</th>
                            <c:choose>
                                <c:when test="${type == 1}">
                                    <th>解绑号码/文件</th>
                                </c:when>
                                <c:when test="${type == 2}">
                                    <th>录入号码/文件</th>
                                </c:when>
                                <c:when test="${type == 3}">
                                    <th>删除号码/文件</th>
                                </c:when>
                            </c:choose>
                            <th>操作时间</th>
                            <th>IP</th>
                            <c:if test="${type != 4}">
                                <th class="center">操作</th>
                            </c:if>
                        </tr>
                        </thead>
                        <tbody id="contentTbody">
                        <!-- 开始循环 -->
                        <c:choose>
                            <c:when test="${not empty operations}">
                                <c:forEach items="${operations}" var="operation">
                                    <tr style="text-align: center">
                                        <td style="text-align:center;width:35px;">
                                            <input role="checkbox" type="checkbox" value="${operation.id}"
                                                   class="cbox checkbox" style="opacity: 1;position: relative">
                                        </td>
                                        <td>${operation.id}</td>
                                        <td>${operation.account}</td>
                                        <td>${operation.role}</td>
                                        <c:if test="${type != 4}">
                                            <td>
                                                <c:if test="${operation.user.type == 0}">系统账号</c:if>
                                                <c:if test="${operation.user.type == 1}">渠道账号</c:if>
                                            </td>
                                        </c:if>
                                        <c:if test="${type == 4}">
                                            <td>${operation.user.channelAff.name}</td>
                                            <td>${operation.module}</td>
                                        </c:if>
                                        <td>${operation.behavior}</td>
                                        <td>${operation.describe}</td>
                                        <c:if test="${type != 4}">
                                            <td>
                                                <c:choose>
                                                    <c:when test="${not empty operation.filename}">
                                                        <div style="">
                                                            <a href="device/downloadExcel?type=-1&fileName=${operation.filename}"
                                                               class="">下载文件[${operation.filename}]</a>
                                                        </div>
                                                    </c:when>
                                                    <c:when test="${not empty operation.imei}">
                                                        ${operation.imei}
                                                    </c:when>
                                                </c:choose>
                                            </td>
                                        </c:if>
                                        <td><fmt:formatDate value="${operation.maketime}"
                                                            pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                        <td>${operation.ip}</td>
                                        <c:if test="${type != 4}">
                                            <td style="width: 60px;">
                                                <div class='hidden-phone visible-desktop btn-group'>
                                                    <c:if test="${fn:contains(butSet, 'del')}">
                                                        <a class='btn btn-mini btn-danger' title="删除"
                                                           onclick="del('${operation.id }');">
                                                            <i class='icon-trash'></i>
                                                        </a>
                                                    </c:if>
                                                </div>
                                            </td>
                                        </c:if>
                                    </tr>
                                </c:forEach>
                            </c:when>
                            <c:otherwise>
                                <tr class="main_info">
                                    <td colspan="10" class="center">没有相关数据</td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                        </tbody>
                    </table>
                    <div class="page-header position-relative">
                        <table style="width:100%;">
                            <tr>
                                <td style="vertical-align:top;">
                                    <div class="pagination"
                                         style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
    <i class="icon-double-angle-up icon-only"></i>
</a>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>

<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
<script type="text/javascript">
    $(function () {
        top.hangge();
        //日期框
        $('.date-picker').datepicker({autoclose: true});
        //下拉框
        $(".chzn-select").chosen({disable_search: true});
        $(".chzn-select-deselect").chosen({allow_single_deselect: true});
    });

    function selectAll(obj) {
        var checkboxs = $("#contentTbody").find("input[type='checkbox']");
        var isChecked = $(obj).is(":checked");
        //严禁使用foreach，jq对象的遍历会使浏览器崩溃
        for (var i = 0; i < checkboxs.length; i++) {
            //临时变量，必须，否则只能选中最后一条记录
            var temp = i;
            $(checkboxs[temp]).prop("checked", isChecked);
        }
    }

    //检索
    function search() {
        var start = $('#startTime').val();
        var end = $('#endTime').val();
        if (end != "" && start != "") {
            if (new Date(start).getTime() > new Date(end).getTime()) {
                $("#endTime").tips({
                    side: 3,
                    msg: '结束时间不能小于开始时间',
                    bg: '#AE81FF',
                    time: 2
                });
                $("#endTime").focus();
                return false;
            }
        }
        top.jzts();
        $("#userForm").submit();
    }

    //删除
    function del(id) {
        bootbox.confirm("是否删除[" + id + "]?", function (result) {
            if (result) {
                top.jzts();
                var postParam = {"ids": id, "type": $("#type").val()};
                var url = "<%=basePath%>operation/del";
                $.post(url, postParam, function (data) {
                    if (data.code == 200) {
                        alert("删除成功")
                        nextPage(${page.currentPage});
                    } else {
                        alert(data.msg)
                    }
                });
            }
        });
    }

    //批量删除
    function batchDel() {
        var ids = "";
        $("#contentTbody input:checkbox[type='checkbox']:checked").each(function (i) {
            if ($(this).val()) {
                ids = ids + $(this).val() + ",";
            }
        });
        if (ids) {
            bootbox.confirm("是否删除选中记录?", function (result) {
                if (result) {
                    top.jzts();
                    var postParam = {"ids": ids, "type": $("#type").val()};
                    var url = "<%=basePath%>operation/del";
                    $.post(url, postParam, function (data) {
                        if (data.code == 200) {
                            alert("成功删除" + data.data + "条记录");
                            nextPage(${page.currentPage});
                        } else {
                            alert(data.msg)
                        }
                    });
                }
            });
        } else {
            alert("请您先选中记录");
        }
    }


</script>
</body>
</html>
